#ifndef FHE_TEXT_RENDERCONTEXT_H
#define FHE_TEXT_RENDERCONTEXT_H

#include <fhe/prims/IRenderContext.h>
#include <map>
#include <vector>

namespace fhe
{
  using namespace core;
  namespace text
  {
    class RenderContext : public IRenderContext2i
    {
    public:
      typedef IRenderContext2i Super;
      
      RenderContext();
      virtual ~RenderContext();
      
      void translate( const Vec2i& pos );
      void rotate( const Rot2i& rot );
      void scale( const Vec2i& scale );
      void popTransform();
      void blit( const std::string& resource );
      
      Vec2i size() const;
      void setSize( const Vec2i& size );
      
      void render();
      void swap();
      
    private:
      typedef std::map< Vec2i, char > Buffer;
      Buffer front_;
      Buffer back_;
      Vec2i size_;
      std::vector< Vec2i > transforms_;

      Vec2i transform() const;
      void renderChar( Vec2i pos, char c );
      void putChar( const Vec2i& pos, char c );
      void putString( const Vec2i& pos, const std::string& s, int align );
    };
  }
}

#endif
